﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Statistics : System.Web.UI.Page
{
    bussiness bus;
    protected void Page_Load(object sender, EventArgs e)
    {
        if(!IsPostBack)
        {
            load_data();
            load_logsentmail();
            load_Customer();
        }
    }
    private void load_data()
    {
        bus = new bussiness();
        grvCount.DataSource = bus.getView_Statistics_count();
        grvCount.DataBind();
        lblTotalCount.Text = bus.getCount_View_Statistics_count().ToString();
        lblToday.Text = bus.getSoLanGuiCardToDay().ToString();
    }
    private void load_logsentmail()
    {
        bus = new bussiness();
        grvTransaction.DataSource = bus.getAllLogSentMail();
        grvTransaction.DataBind();
    }
    private int count_subcrible = 0;
    private int count_normal = 0;
    private int count_total = 0;
    private void load_Customer()
    {
        bus = new bussiness();
        List<Customer> lstCustomer = bus.getAllCustomer();
        grvCustomer.DataSource = lstCustomer;
        grvCustomer.DataBind();
        foreach (Customer c in lstCustomer)
        {
            count_total++;
            if (c.Status == "subcrible")
            {
                count_subcrible++;
            }
            if (c.Status == "normal")
            {
                count_normal++;
            }
        }
        lblTotalCustumer.Text = count_total.ToString();
        lblCustomerNormal.Text = count_normal.ToString();
        lblCustomerSubcribe.Text = count_subcrible.ToString();
    }
    protected void btnUpdate_Click(object sender, EventArgs e)
    {
        load_data();
    }
    protected void grvTransaction_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvTransaction.PageIndex = e.NewPageIndex;
        load_logsentmail();
    }
    protected void grvCount_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvCount.PageIndex = e.NewPageIndex;
        load_logsentmail();
    }
    protected void grvCustomer_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        grvCustomer.PageIndex = e.NewPageIndex;
        load_logsentmail();
    }
}